package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.feign.VodFeignService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.eduservice.entity.EduVideo;
import com.atguigu.eduservice.service.EduVideoService;
import com.atguigu.eduservice.mapper.EduVideoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.concurrent.CompletableFuture;

/**
 * @author kabuda
 * @description 针对表【edu_video(课程视频)】的数据库操作Service实现
 * @createDate 2023-04-24 14:04:24
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo>
        implements EduVideoService {

    @Autowired
    private VodFeignService vodFeignService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void removeVideo(String videoId) {
        EduVideo video = this.getById(videoId);
        //删除小节
        this.removeById(videoId);
        //异步删除
        CompletableFuture.runAsync(() -> {
            //删除视频点播
            if (StringUtils.hasText(video.getVideoSourceId())) {
                vodFeignService.delete(video.getVideoSourceId());
            }

        });
    }
}




